// nodejs 处理 get 请求
const http = require('http')
const qs = require('qs')

const server = http.createServer((req, res) => {
    const method = req.method
    console.log('method ', method) // GET
    const url = req.url // 获取请求的完整 url
    console.log('url', url)
    req.query = qs.parse(url.split('?')[1]) // 解析 querystring
    console.log('req.query', req.query) 
    res.end(
        JSON.stringify(req.query) // 将 querystring 返回
    )
})

server.listen(8000)
console.log('ok');